<!DOCTYPE html><html lang="en" data-theme="light"><head><meta charset="UTF-8"><meta name="referrer" content="no-referrer"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0,viewport-fit=cover"><title>Golang-web/http框架 | Welcome,Guys,Join Me for the AIminminAI Episode!</title><meta name="author" content="Hu hb"><meta name="copyright" content="Hu hb"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="@TOC  前言云时代已经逐渐到来，在工作中学习中，我们时不时会用到Go语言，那就开始学起吧，与诸君共勉。 Go(lang)提供了很好的net&#x2F;http库，基于此再造框架比较简单快速，Go中常用的三个web框架【go所有的安装都是使用go get安装（类似于git-clone）】Gin 一个Gin框架的请求处理代码块固定格式：请求,处理请求的回调函数1234567891011121314">
<meta property="og:type" content="article">
<meta property="og:title" content="Golang-web&#x2F;http框架">
<meta property="og:url" content="https://aiminminai.gitee.io/aiminminai/2024/03/27/Golang-web-http%E6%A1%86%E6%9E%B6/index.html">
<meta property="og:site_name" content="Welcome,Guys,Join Me for the AIminminAI Episode!">
<meta property="og:description" content="@TOC  前言云时代已经逐渐到来，在工作中学习中，我们时不时会用到Go语言，那就开始学起吧，与诸君共勉。 Go(lang)提供了很好的net&#x2F;http库，基于此再造框架比较简单快速，Go中常用的三个web框架【go所有的安装都是使用go get安装（类似于git-clone）】Gin 一个Gin框架的请求处理代码块固定格式：请求,处理请求的回调函数1234567891011121314">
<meta property="og:locale" content="en_US">
<meta property="og:image" content="https://aiminminai.gitee.io/aiminminai/img/avatar.jpg">
<meta property="article:published_time" content="2024-03-27T15:27:12.000Z">
<meta property="article:modified_time" content="2024-03-27T15:50:02.525Z">
<meta property="article:author" content="Hu hb">
<meta property="article:tag" content="Code Snippet">
<meta property="article:tag" content="VS工具、插件的使用">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://aiminminai.gitee.io/aiminminai/img/avatar.jpg"><link rel="shortcut icon" href="/aiminminai/img/favicon.png"><link rel="canonical" href="https://aiminminai.gitee.io/aiminminai/2024/03/27/Golang-web-http%E6%A1%86%E6%9E%B6/index.html"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//fonts.googleapis.com" crossorigin=""/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/aiminminai/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox/fancybox.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Titillium+Web&amp;display=swap" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = {
  root: '/aiminminai/',
  algolia: undefined,
  localSearch: undefined,
  translate: undefined,
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false},
  copy: {
    success: 'Copy successfully',
    error: 'Copy error',
    noSupport: 'The browser does not support'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: 'days',
  dateSuffix: {
    just: 'Just',
    min: 'minutes ago',
    hour: 'hours ago',
    day: 'days ago',
    month: 'months ago'
  },
  copyright: {"limitCount":50,"languages":{"author":"Author: Hu hb","link":"Link: ","source":"Source: Welcome,Guys,Join Me for the AIminminAI Episode!","info":"Copyright is owned by the author. For commercial reprints, please contact the author for authorization. For non-commercial reprints, please indicate the source."}},
  lightbox: 'fancybox',
  Snackbar: undefined,
  source: {
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: false,
  isAnchor: false,
  percent: {
    toc: true,
    rightside: true,
  },
  autoDarkmode: false
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: 'Golang-web/http框架',
  isPost: true,
  isHome: false,
  isHighlightShrink: true,
  isToc: true,
  postUpdate: '2024-03-27 23:50:02'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
    win.getCSS = (url,id = false) => new Promise((resolve, reject) => {
      const link = document.createElement('link')
      link.rel = 'stylesheet'
      link.href = url
      if (id) link.id = id
      link.onerror = reject
      link.onload = link.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        link.onload = link.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(link)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const detectApple = () => {
      if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
    })(window)</script><meta name="generator" content="Hexo 6.3.0"></head><body><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="/aiminminai/img/avatar.jpg" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="sidebar-site-data site-data is-center"><a href="/aiminminai/archives/"><div class="headline">Articles</div><div class="length-num">29</div></a><a href="/aiminminai/tags/"><div class="headline">Tags</div><div class="length-num">47</div></a><a href="/aiminminai/categories/"><div class="headline">Categories</div><div class="length-num">42</div></a></div><hr class="custom-hr"/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/aiminminai/"><i class="fa-fw fas fa-home"></i><span> Home(主页)</span></a></div><div class="menus_item"><a class="site-page" href="/aiminminai/archives/"><i class="fa-fw fas fa-archive"></i><span> Archives(那些年的知识归档)</span></a></div><div class="menus_item"><a class="site-page" href="/aiminminai/tags/"><i class="fa-fw fas fa-tags"></i><span> Tags(那些年的知识标签)</span></a></div><div class="menus_item"><a class="site-page" href="/aiminminai/categories/"><i class="fa-fw fas fa-folder-open"></i><span> Categories(那些年的工作经验)</span></a></div><div class="menus_item"><a class="site-page" href="/aiminminai/link/"><i class="fa-fw fas fa-link"></i><span> Link(那些年的八股)</span></a></div><div class="menus_item"><a class="site-page" href="/aiminminai/game/"><i class="fa-fw fas fa-heart"></i><span> Game Area(游戏专区，学&amp;玩)</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url('/aiminminai/img/JingSeOne.jpg')"><nav id="nav"><span id="blog-info"><a href="/aiminminai/" title="Welcome,Guys,Join Me for the AIminminAI Episode!"><span class="site-name">Welcome,Guys,Join Me for the AIminminAI Episode!</span></a></span><div id="menus"><div class="menus_items"><div class="menus_item"><a class="site-page" href="/aiminminai/"><i class="fa-fw fas fa-home"></i><span> Home(主页)</span></a></div><div class="menus_item"><a class="site-page" href="/aiminminai/archives/"><i class="fa-fw fas fa-archive"></i><span> Archives(那些年的知识归档)</span></a></div><div class="menus_item"><a class="site-page" href="/aiminminai/tags/"><i class="fa-fw fas fa-tags"></i><span> Tags(那些年的知识标签)</span></a></div><div class="menus_item"><a class="site-page" href="/aiminminai/categories/"><i class="fa-fw fas fa-folder-open"></i><span> Categories(那些年的工作经验)</span></a></div><div class="menus_item"><a class="site-page" href="/aiminminai/link/"><i class="fa-fw fas fa-link"></i><span> Link(那些年的八股)</span></a></div><div class="menus_item"><a class="site-page" href="/aiminminai/game/"><i class="fa-fw fas fa-heart"></i><span> Game Area(游戏专区，学&amp;玩)</span></a></div></div><div id="toggle-menu"><a class="site-page" href="javascript:void(0);"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">Golang-web/http框架</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">Created</span><time class="post-meta-date-created" datetime="2024-03-27T15:27:12.000Z" title="Created 2024-03-27 23:27:12">2024-03-27</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">Updated</span><time class="post-meta-date-updated" datetime="2024-03-27T15:50:02.525Z" title="Updated 2024-03-27 23:50:02">2024-03-27</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/aiminminai/categories/Golang/">Golang</a><i class="fas fa-angle-right post-meta-separator"></i><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/aiminminai/categories/Golang/%E5%9F%BA%E6%9C%AC%E5%8A%9F/">基本功</a><i class="fas fa-angle-right post-meta-separator"></i><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/aiminminai/categories/Golang/%E5%9F%BA%E6%9C%AC%E5%8A%9F/web-http%E6%A1%86%E6%9E%B6/">web/http框架</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="Golang-web/http框架"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">Post View:</span><span id="busuanzi_value_page_pv"><i class="fa-solid fa-spinner fa-spin"></i></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><p>@<a href="%E6%96%87%E7%AB%A0%E7%9B%AE%E5%BD%95">TOC</a></p>
<hr>
<h1 id="前言"><a href="#前言" class="headerlink" title="前言"></a>前言</h1><p>云时代已经逐渐到来，在工作中学习中，我们时不时会用到Go语言，那就开始学起吧，与诸君共勉。</p>
<h1 id="Go-lang-提供了很好的net-http库，基于此再造框架比较简单快速，Go中常用的三个web框架【go所有的安装都是使用go-get安装（类似于git-clone）】"><a href="#Go-lang-提供了很好的net-http库，基于此再造框架比较简单快速，Go中常用的三个web框架【go所有的安装都是使用go-get安装（类似于git-clone）】" class="headerlink" title="Go(lang)提供了很好的net&#x2F;http库，基于此再造框架比较简单快速，Go中常用的三个web框架【go所有的安装都是使用go get安装（类似于git-clone）】"></a>Go(lang)提供了很好的net&#x2F;http库，基于此再造框架比较简单快速，Go中常用的三个web框架【go所有的安装都是使用go get安装（类似于git-clone）】</h1><h2 id="Gin"><a href="#Gin" class="headerlink" title="Gin"></a>Gin</h2><ul>
<li>一个Gin框架的请求处理代码块固定格式：请求,处理请求的回调函数<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><code class="hljs plaintext">package main<br><br>import (<br>   &quot;github.com/gin-gonic/gin&quot;<br>   &quot;github.com/thinkerou/favicon&quot;<br>   &quot;net/http&quot;<br>)<br><br>func main() &#123;<br>   //创建一个gin服务，结合访问地址+端口处理咱们的请求与响应<br>   ginServer := gin.Default()<br>    <br>    ginServer.GET(&quot;/user/info&quot;, func(context *gin.Context)&#123;<br>        ...    <br>    &#125;)<br><br>&#125;<br></code></pre></td></tr></table></figure></li>
<li>通过几行代码就可以启动一个服务<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><code class="hljs plaintext">package main<br><br>import &quot;github.com/gin-gonic/gin&quot;<br><br>func main() &#123;<br>   //创建一个gin服务，结合访问地址+端口处理咱们的请求与响应<br>   ginServer := gin.Default()<br><br>   /**<br>    * 模拟一个get请求,给浏览器发送一个请求，相当于给浏览器打个招呼<br>    * context 代表请求的上下文对象<br>    */<br>   ginServer.GET(&quot;/myfirstgodemo&quot;, func(context *gin.Context) &#123;<br>      context.JSON(200, gin.H&#123;&quot;MSH&quot;: &quot;IM HHB&quot;&#125;)<br>   &#125;)<br><br>   //指定服务器运行端口<br>   ginServer.Run(&quot;:8082&quot;)<br>&#125;<br><br></code></pre></td></tr></table></figure></li>
<li>新建项目后，尽量在项目中先建一个go.mod用来管理咱们的包结构【因为项目中可能包很多】，跟maven差不多<ul>
<li>import导入时如果报错，去settings中的GO MUDULE配置GOPROXY&#x3D;”…这里的内容去命令提示符中，输入go env，复制键值对的GOPROXY的值”，然后确定即可</li>
<li>检查三个地方</li>
</ul>
</li>
<li>GIN框架经验总结：指定服务器端口时端口前面没有加冒号，导致报错ginServer.Run(“:8082”)<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><code class="hljs plaintext">func main() &#123;<br>   //创建一个gin服务，结合访问地址+端口处理咱们的请求与响应<br>   ginServer := gin.Default()<br><br>   /**<br>    * 模拟一个get请求,给浏览器发送一个请求，相当于给浏览器打个招呼<br>    * context 代表请求的上下文对象<br>    */<br>   ginServer.GET(&quot;/hell&quot;, func(context *gin.Context) &#123;<br>      context.JSON(200, gin.H&#123;&quot;MSH&quot;: &quot;IM HHB&quot;&#125;)<br>   &#125;)<br><br>   //指定服务器运行端口<br>   ginServer.Run(&quot;:8082&quot;)<br>&#125;<br></code></pre></td></tr></table></figure></li>
</ul>
<h1 id="给前端页面标题栏指定照片："><a href="#给前端页面标题栏指定照片：" class="headerlink" title="给前端页面标题栏指定照片："></a>给前端页面标题栏指定照片：</h1><h2 id="你得先找一个-ico或者照片啥的，放到你的项目中，这不就是前端项目的常用手段嘛。ginServer-Use-favicon-New-“-cartonPhone-jpg”-。然后就得go-get-“github-com-thinkerou-favicon”下载，然后再import-“github-com-thinkerou-favicon”导入这个包，favicon-New这个函数才能用"><a href="#你得先找一个-ico或者照片啥的，放到你的项目中，这不就是前端项目的常用手段嘛。ginServer-Use-favicon-New-“-cartonPhone-jpg”-。然后就得go-get-“github-com-thinkerou-favicon”下载，然后再import-“github-com-thinkerou-favicon”导入这个包，favicon-New这个函数才能用" class="headerlink" title="你得先找一个.ico或者照片啥的，放到你的项目中，这不就是前端项目的常用手段嘛。ginServer.Use(favicon.New(“.&#x2F;cartonPhone.jpg”))。然后就得go get “github.com&#x2F;thinkerou&#x2F;favicon”下载，然后再import “github.com&#x2F;thinkerou&#x2F;favicon”导入这个包，favicon.New这个函数才能用"></a>你得先找一个.ico或者照片啥的，放到你的项目中，这不就是前端项目的常用手段嘛。ginServer.Use(favicon.New(“.&#x2F;cartonPhone.jpg”))。然后就得go get “github.com&#x2F;thinkerou&#x2F;favicon”下载，然后再import “github.com&#x2F;thinkerou&#x2F;favicon”导入这个包，favicon.New这个函数才能用</h2><h2 id="restful-api（GIN支持）"><a href="#restful-api（GIN支持）" class="headerlink" title="restful api（GIN支持）"></a>restful api（GIN支持）</h2><ul>
<li>以前写路由地址相关代码：get &#x2F;user   post &#x2F;create_user   post  &#x2F;update_user   post &#x2F;delete_user，不同的请求要对应不同的路由地址，通过URL和请求来进行请求隔离。编写起来很麻烦，没有统一的那个感觉；<ul>
<li>而用了RESTful API之后，get &#x2F;user  post  &#x2F;user  put &#x2F;user  delete  &#x2F;user，通过不同的请求来执行不同的功能，通过不同的请求方式来隔离，不用频繁修改路由地址</li>
<li>项目中集成不同的请求：GET、POST、DELETE、PUT<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br></pre></td><td class="code"><pre><code class="hljs plaintext">package main<br><br>import (<br>&quot;github.com/gin-gonic/gin&quot;<br>&quot;github.com/thinkerou/favicon&quot;<br>)<br><br>func main() &#123;<br>//创建一个gin服务，结合访问地址+端口处理咱们的请求与响应<br>ginServer := gin.Default()<br>/**<br>    * 模拟一个get请求,给浏览器发送一个请求，相当于给浏览器打个招呼<br>    * context 代表请求的上下文对象<br>    */<br>ginServer.GET(&quot;/my first go demo&quot;, func(context *gin.Context) &#123;<br>    context.JSON(200, gin.H&#123;&quot;Min&quot;: &quot;I fall in love with you &quot;&#125;)<br>&#125;)<br>ginServer.POST(&quot;user&quot;, func(context *gin.Context) &#123;<br>    context.JSON(200, gin.H&#123;&quot;msg:&quot;: &quot;post type&quot;&#125;)<br>&#125;)<br>ginServer.PUT(&quot;/user&quot;)<br>ginServer.DELETE(&quot;/user&quot;)<br><br>//指定服务器运行端口<br>ginServer.Run(&quot;:8888&quot;)<br>&#125;<br><br></code></pre></td></tr></table></figure></li>
</ul>
</li>
<li>可以用postman测试post请求的结果</li>
</ul>
<h2 id="咱们写好的前端动态静态页面，现在就可以试着用go调用呼应了"><a href="#咱们写好的前端动态静态页面，现在就可以试着用go调用呼应了" class="headerlink" title="咱们写好的前端动态静态页面，现在就可以试着用go调用呼应了"></a>咱们写好的前端动态静态页面，现在就可以试着用go调用呼应了</h2><ul>
<li>加载静态页面：【有全局的和单个html页面，你单个的要一个文件一个文件写出来，太多了。全局的好用一点】ginServer.LoadHTMLGlob(“templates&#x2F;*”)</li>
<li>返回或者响应：<ul>
<li>返回JSON数据：咱们ginServer.GET(…)回调函数中写的是context.JSON…</li>
<li>返回HTML页面：那就是ginServer.GET(…)回调函数中写的是context.HTML…<ul>
<li>当然，templates中的*.html文件、static中的*.js、*.css文件都可以响应</li>
</ul>
</li>
</ul>
</li>
</ul>
<h2 id="获取请求中的参数"><a href="#获取请求中的参数" class="headerlink" title="获取请求中的参数"></a>获取请求中的参数</h2><ul>
<li>传统的url中用？拼接的分数：url?userid&#x3D;xxx&amp;username&#x3D;hhb…</li>
<li>RESTful风格的请求参数：&#x2F;usr&#x2F;info&#x2F;1&#x2F;hhb</li>
</ul>
<h2 id="重定向、路由组等就是context-xxx"><a href="#重定向、路由组等就是context-xxx" class="headerlink" title="重定向、路由组等就是context.xxx"></a>重定向、路由组等就是context.xxx</h2><h2 id="自定义go中间件：拦截器"><a href="#自定义go中间件：拦截器" class="headerlink" title="自定义go中间件：拦截器"></a>自定义go中间件：拦截器</h2><ul>
<li>浏览器前端发了一个请求，比如&#x2F;user&#x2F;delete，这个请求到后端来处理，此时，此时就可以加一个拦截器进行预处理【登陆授权、验证、分页、各种特征信息统计】<ul>
<li>step1:先定义一个中间件或者叫中间逻辑func myHandlerDemo() gin.HandlerFunc {…}</li>
<li>step2:注册中间件或者中间逻辑：在main函数中ginServer :&#x3D; gin.Default()   ginServer.Use(myHandlerDemo())</li>
<li>step3:在响应的地方调用ginServer.GET(“&#x2F;…访问路由”， myHandlerDemo（）， func(context *gin.Context){…}…)<ul>
<li>你在某个ginServer.GET(“&#x2F;…访问路由”，中使用myHandlerDemo（）就是说明给某一个请求使用，要是光注册进来没给具体的哪个ginServer.GET(“&#x2F;…访问路由”，中放myHandlerDemo（），说明是全局使用这个myHandlerDemo（）<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br></pre></td><td class="code"><pre><code class="hljs plaintext">package main<br><br>import (<br>   &quot;encoding/json&quot;<br>   &quot;github.com/gin-gonic/gin&quot;<br>   &quot;github.com/thinkerou/favicon&quot;<br>   &quot;net/http&quot;<br>)<br><br>//自定义go中间件 拦截器<br>func myHandlerDemo() gin.HandlerFunc &#123;<br>   return func(context *gin.Context) &#123;<br>      //通过自定义的中间件，设置的值，在后续处理只要调用了这个中间件的都可以拿到这里的参数<br>      context.Set(&quot;usersession&quot;, &quot;userid-1&quot;)<br><br>      /**<br>       * 加个if判断<br>       * if xxx.xxx&#123;<br>       *   context.Next() //放行<br>       * &#125;<br>       * context.Abort() //阻止通过<br>       */<br>   &#125;<br>&#125;<br><br>func main() &#123;<br>   //创建一个gin服务，结合访问地址+端口处理咱们的请求与响应<br>   ginServer := gin.Default()<br>   ginServer.Use(favicon.New(&quot;./cartonPhone.jpg&quot;))<br><br>   //呼应前端玩法一：在这里就可以加载前端的静态页面<br>   ginServer.LoadHTMLGlob(&quot;templates/*&quot;)<br>   //呼应前端玩法三：加载资源文件<br>   ginServer.Static(&quot;/static&quot;, &quot;./static&quot;)<br><br>   /**<br>    * 模拟一个get请求,给浏览器发送一个请求，相当于给浏览器打个招呼<br>    * context 代表请求的上下文对象<br>    */<br>   ginServer.GET(&quot;/my first go demo&quot;, func(context *gin.Context) &#123;<br>      context.JSON(200, gin.H&#123;&quot;Min&quot;: &quot;I fall in love with you &quot;&#125;)<br>   &#125;)<br><br>   //呼应前端玩法二：呼应或者叫返回一个页面给前端。跟返回JSON一样，无非就是回调函数context.点的东西不一样而已<br>   ginServer.GET(&quot;/staticView&quot;, func(context *gin.Context) &#123;<br>      context.HTML(http.StatusOK, &quot;index.html&quot;, gin.H&#123;<br>         &quot;msg&quot;: &quot;minmin,i fall in love with you minmin in static view&quot;,<br>      &#125;)<br>   &#125;)<br><br>   //接收前段传递过来的参数,比如例子：url?userid=xxx&amp;username=hhb<br>   ginServer.GET(&quot;/learnParam&quot;, func(context *gin.Context) &#123;<br>      userid := context.Query(&quot;userid&quot;)<br>      username := context.Query(&quot;username&quot;)<br>      context.JSON(http.StatusOK, gin.H&#123;<br>         &quot;userid&quot;:   userid,<br>         &quot;username&quot;: username,<br>      &#125;)<br>   &#125;)<br><br>   //接收前段传递过来的RESTful风格的参数,比如例子：url?userid=xxx&amp;username=hhb<br>   ginServer.GET(&quot;/learnRestfulApi/:userid/:username&quot;, func(context *gin.Context) &#123;<br>      userid := context.Param(&quot;userid&quot;)<br>      username := context.Param(&quot;username&quot;)<br>      context.JSON(http.StatusOK, gin.H&#123;<br>         &quot;userid&quot;:   userid,<br>         &quot;username&quot;: username,<br>      &#125;)<br>   &#125;)<br><br>   //前端传JSON格式的数据到后端<br>   ginServer.POST(&quot;/sendJsonData&quot;, func(context *gin.Context) &#123;<br>      //从请求体中获取数据<br>      b, _ := context.GetRawData()<br><br>      var m map[string]interface&#123;&#125;<br>      //通过json序列化包装为json数据 []byte<br>      _ = json.Unmarshal(b, &amp;m)<br>      context.JSON(http.StatusOK, m)<br>   &#125;)<br><br>   ginServer.POST(&quot;/learnForm/demo&quot;, func(context *gin.Context) &#123;<br>      username := context.PostForm(&quot;username&quot;)<br>      password := context.PostForm(&quot;password&quot;)<br>      context.JSON(http.StatusOK, gin.H&#123;<br>         &quot;msg&quot;:      &quot;ok&quot;,<br>         &quot;username&quot;: username,<br>         &quot;password&quot;: password,<br>      &#125;)<br><br>   &#125;)<br>   //指定服务器运行端口<br>   ginServer.Run(&quot;:8888&quot;)<br>&#125;<br><br></code></pre></td></tr></table></figure></li>
</ul>
</li>
</ul>
</li>
</ul>
<h2 id="Beego：快速开发go应用，提供了很多现成的组件"><a href="#Beego：快速开发go应用，提供了很多现成的组件" class="headerlink" title="Beego：快速开发go应用，提供了很多现成的组件"></a>Beego：快速开发go应用，提供了很多现成的组件</h2><h3 id="Iris"><a href="#Iris" class="headerlink" title="Iris"></a>Iris</h3><ul>
<li>最快的Go语言Web框架，支持MVC三层架构</li>
</ul>
<h2 id="Go语言ORM库：xorm，使得数据库操作非常简便"><a href="#Go语言ORM库：xorm，使得数据库操作非常简便" class="headerlink" title="Go语言ORM库：xorm，使得数据库操作非常简便"></a>Go语言ORM库：xorm，使得数据库操作非常简便</h2><ul>
<li>sqlx这个包就可以连接数据库</li>
<li>官网：<a target="_blank" rel="noopener" href="https://xorm.io/">https://xorm.io/</a></li>
<li>同步结构体到数据库：<a target="_blank" rel="noopener" href="https://gitea.com/xorm/xorm/src/branch/master/README_CN.md#%E5%BF%AB%E9%80%9F%E5%BC%80%E5%A7%8B">https://gitea.com/xorm/xorm/src/branch/master/README_CN.md#%E5%BF%AB%E9%80%9F%E5%BC%80%E5%A7%8B</a><ul>
<li>java中是实体中的成员变量或者叫成员属性对应数据库中字段，而go中用的是结构体，结构体中的属性对应数据库中的字段属性，而且你想要增加或者减少数据库中字段时直接在结构体中增加减少字段，然后err &#x3D; engine.Sync(new(User))，然后执行代码即可</li>
<li>注意，确定有可能出现err的地方可以加if判断</li>
</ul>
</li>
<li>CRUD:<a target="_blank" rel="noopener" href="https://gitea.com/xorm/xorm/src/branch/master/README_CN.md#%E5%BF%AB%E9%80%9F%E5%BC%80%E5%A7%8B">https://gitea.com/xorm/xorm/src/branch/master/README_CN.md#%E5%BF%AB%E9%80%9F%E5%BC%80%E5%A7%8B</a><ul>
<li>engine.Insert(&amp;user) &#x2F;&#x2F;像这种engine.Insert(user)只填入这个对象也行。但是有时候这个CRUD方法有时候会给这个对象回填一些信息啥的，这时候要保证CRUD里面用的user和外面的user是同一个，所以用指针对象去保证是同一个对象</li>
<li>engine.UPDATE:更新数据，默认只更新非空和非0的字段</li>
<li>engine.DELETE:删除记录，删除必须至少有一个条件，否则会报错</li>
<li>engine.Exec：执行一个SQL语句</li>
</ul>
</li>
<li>数据查询：<ul>
<li>Query：最原始的支持SQL查询，返回类型为[]map[string][]byte</li>
<li>QueryString返回[]map[string]string</li>
<li>QueryInterface返回[]map[string]interface{}</li>
<li>Get查询单条记录</li>
<li>Find查询多条记录</li>
<li>Count获取记录条数</li>
<li>Iterate和Rows根据条件遍历数据</li>
</ul>
</li>
</ul>
<h2 id="Go的经典应用：gRPC"><a href="#Go的经典应用：gRPC" class="headerlink" title="Go的经典应用：gRPC"></a>Go的经典应用：gRPC</h2><ul>
<li>官方文档：<a target="_blank" rel="noopener" href="https://grpc.io/">https://grpc.io/</a></li>
<li>中文文档：<a target="_blank" rel="noopener" href="https://doc.oschina.net/grpc">https://doc.oschina.net/grpc</a></li>
</ul>
<hr>
<h1 id="巨人的肩膀"><a href="#巨人的肩膀" class="headerlink" title="巨人的肩膀"></a>巨人的肩膀</h1><ul>
<li><a target="_blank" rel="noopener" href="https://learn.microsoft.com/zh-cn/dotnet/csharp/fundamentals/coding-style/coding-conventions">https://learn.microsoft.com/zh-cn/dotnet/csharp/fundamentals/coding-style/coding-conventions</a></li>
<li>菜鸟教程</li>
</ul>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">Author: </span><span class="post-copyright-info"><a href="https://aiminminai.gitee.io/aiminminai">Hu hb</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">Link: </span><span class="post-copyright-info"><a href="https://aiminminai.gitee.io/aiminminai/2024/03/27/Golang-web-http%E6%A1%86%E6%9E%B6/">https://aiminminai.gitee.io/aiminminai/2024/03/27/Golang-web-http%E6%A1%86%E6%9E%B6/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">Copyright Notice: </span><span class="post-copyright-info">All articles in this blog are licensed under <a target="_blank" rel="noopener" href="https://creativecommons.org/licenses/by-nc-sa/4.0/">CC BY-NC-SA 4.0</a> unless stating additionally.</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/aiminminai/tags/Code-Snippet/">Code Snippet</a><a class="post-meta__tags" href="/aiminminai/tags/VS%E5%B7%A5%E5%85%B7%E3%80%81%E6%8F%92%E4%BB%B6%E7%9A%84%E4%BD%BF%E7%94%A8/">VS工具、插件的使用</a></div><div class="post_share"><div class="social-share" data-image="/aiminminai/img/avatar.jpg" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/js/social-share.min.js" defer></script></div></div><div class="post-reward"><div class="reward-button"><i class="fas fa-qrcode"></i> Donate</div><div class="reward-main"><ul class="reward-all"><li class="reward-item"><a href="/aiminminai/img/WeChat.jpg" target="_blank"><img class="post-qr-code-img" src="/aiminminai/img/WeChat.jpg" alt="wechat"/></a><div class="post-qr-code-desc">wechat</div></li><li class="reward-item"><a href="/aiminminai/img/Alipay.jpg" target="_blank"><img class="post-qr-code-img" src="/aiminminai/img/Alipay.jpg" alt="alipay"/></a><div class="post-qr-code-desc">alipay</div></li></ul></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/aiminminai/2024/03/28/%E9%A1%B9%E7%9B%AE%E5%BC%80%E5%8F%91%E6%80%BB%E7%BB%93%E4%B9%8BC-%E5%86%99%E4%BA%86%E4%B8%80%E4%B8%AA%E4%B8%8A%E4%BD%8D%E6%9C%BA%E9%A1%B5%E9%9D%A2%EF%BC%8C%E8%BD%AF%E4%BB%B6%E5%8D%A1%E6%AD%BB%E4%BA%86%EF%BC%9F%EF%BC%9F%EF%BC%9F/" title="项目开发总结之C#写了一个上位机页面，软件卡死了？？？"><div class="cover" style="background: var(--default-bg-color)"></div><div class="pagination-info"><div class="label">Previous Post</div><div class="prev_info">项目开发总结之C#写了一个上位机页面，软件卡死了？？？</div></div></a></div><div class="next-post pull-right"><a href="/aiminminai/2024/03/24/Golang-%E7%BB%83%E5%9F%BA%E6%9C%AC%E5%8A%9F%EF%BC%9A%E6%89%8E%E9%A9%AC%E6%AD%A5%E3%80%81%E7%BB%83%E6%8A%95%E7%AF%AE/" title="Golang-练基本功：扎马步、练投篮、练运球"><div class="cover" style="background: var(--default-bg-color)"></div><div class="pagination-info"><div class="label">Next Post</div><div class="next_info">Golang-练基本功：扎马步、练投篮、练运球</div></div></a></div></nav><div class="relatedPosts"><div class="headline"><i class="fas fa-thumbs-up fa-fw"></i><span>Related Articles</span></div><div class="relatedPosts-list"><div><a href="/aiminminai/2023/09/03/Code-Snippet%E7%9A%84%E4%BD%BF%E7%94%A8/" title="Code Snippet的使用"><div class="cover" style="background: var(--default-bg-color)"></div><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2023-09-03</div><div class="title">Code Snippet的使用</div></div></a></div><div><a href="/aiminminai/2024/03/24/Golang-%E7%BB%83%E5%9F%BA%E6%9C%AC%E5%8A%9F%EF%BC%9A%E6%89%8E%E9%A9%AC%E6%AD%A5%E3%80%81%E7%BB%83%E6%8A%95%E7%AF%AE/" title="Golang-练基本功：扎马步、练投篮、练运球"><div class="cover" style="background: var(--default-bg-color)"></div><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2024-03-24</div><div class="title">Golang-练基本功：扎马步、练投篮、练运球</div></div></a></div></div></div></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src="/aiminminai/img/avatar.jpg" onerror="this.onerror=null;this.src='/aiminminai/img/friend_404.gif'" alt="avatar"/></div><div class="author-info__name">Hu hb</div><div class="author-info__description">寻寻觅觅，原来未来的你，在这里呀</div></div><div class="card-info-data site-data is-center"><a href="/aiminminai/archives/"><div class="headline">Articles</div><div class="length-num">29</div></a><a href="/aiminminai/tags/"><div class="headline">Tags</div><div class="length-num">47</div></a><a href="/aiminminai/categories/"><div class="headline">Categories</div><div class="length-num">42</div></a></div><a id="card-info-btn" target="_blank" rel="noopener" href="https://gitee.com/aiminminai"><i class="Gitee"></i><span>Follow Me</span></a><div class="card-info-social-icons is-center"><a class="social-icon" href="mailto:min221forever@gmail.com" target="_blank" title="Email"><i class="fas fa-envelope"></i></a><a class="social-icon" href="https://github.com/YWMHHBAIminminAI" target="_blank" title="Github"><i class="fab fa-github"></i></a><a class="social-icon" href="https://blog.csdn.net/m0_52436398?type=blog" target="_blank" title="CSDN"><i class="fa fa-book-open"></i></a><a class="social-icon" href="https://gitee.com/aiminminai" target="_blank" title="Gitee"><i class="fa fa-g"></i></a></div></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn fa-shake"></i><span>Announcement</span></div><div class="announcement_content"><b><font color="#e66b6d">掬</font> <font color="#e66d98">水</font> <font color="#e66cc6">月</font> <font color="#cc6de6">在</font> <font        color="#9770e6">手</font> <font color="#6d93e6">，</font> <font color="#6fcde6">弄</font> <font color="#72e6b6">花</font> <font color="#72e689">香</font> <font color="#99e670">满</font> <font color="#cde670">衣</font> <p align="center"><img src="https://haiyong.site/img/img-blog.csdnimg.cn/f7384c88956d4378b72e47548e19c9f8.gif" width="50" alt="mao"></p> <p align="center">微信号：phone_15902953075</p> <p align="center">QQ号：1317957931</p></div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>Catalog</span><span class="toc-percentage"></span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#%E5%89%8D%E8%A8%80"><span class="toc-number">1.</span> <span class="toc-text">前言</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#Go-lang-%E6%8F%90%E4%BE%9B%E4%BA%86%E5%BE%88%E5%A5%BD%E7%9A%84net-http%E5%BA%93%EF%BC%8C%E5%9F%BA%E4%BA%8E%E6%AD%A4%E5%86%8D%E9%80%A0%E6%A1%86%E6%9E%B6%E6%AF%94%E8%BE%83%E7%AE%80%E5%8D%95%E5%BF%AB%E9%80%9F%EF%BC%8CGo%E4%B8%AD%E5%B8%B8%E7%94%A8%E7%9A%84%E4%B8%89%E4%B8%AAweb%E6%A1%86%E6%9E%B6%E3%80%90go%E6%89%80%E6%9C%89%E7%9A%84%E5%AE%89%E8%A3%85%E9%83%BD%E6%98%AF%E4%BD%BF%E7%94%A8go-get%E5%AE%89%E8%A3%85%EF%BC%88%E7%B1%BB%E4%BC%BC%E4%BA%8Egit-clone%EF%BC%89%E3%80%91"><span class="toc-number">2.</span> <span class="toc-text">Go(lang)提供了很好的net&#x2F;http库，基于此再造框架比较简单快速，Go中常用的三个web框架【go所有的安装都是使用go get安装（类似于git-clone）】</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#Gin"><span class="toc-number">2.1.</span> <span class="toc-text">Gin</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E7%BB%99%E5%89%8D%E7%AB%AF%E9%A1%B5%E9%9D%A2%E6%A0%87%E9%A2%98%E6%A0%8F%E6%8C%87%E5%AE%9A%E7%85%A7%E7%89%87%EF%BC%9A"><span class="toc-number">3.</span> <span class="toc-text">给前端页面标题栏指定照片：</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%BD%A0%E5%BE%97%E5%85%88%E6%89%BE%E4%B8%80%E4%B8%AA-ico%E6%88%96%E8%80%85%E7%85%A7%E7%89%87%E5%95%A5%E7%9A%84%EF%BC%8C%E6%94%BE%E5%88%B0%E4%BD%A0%E7%9A%84%E9%A1%B9%E7%9B%AE%E4%B8%AD%EF%BC%8C%E8%BF%99%E4%B8%8D%E5%B0%B1%E6%98%AF%E5%89%8D%E7%AB%AF%E9%A1%B9%E7%9B%AE%E7%9A%84%E5%B8%B8%E7%94%A8%E6%89%8B%E6%AE%B5%E5%98%9B%E3%80%82ginServer-Use-favicon-New-%E2%80%9C-cartonPhone-jpg%E2%80%9D-%E3%80%82%E7%84%B6%E5%90%8E%E5%B0%B1%E5%BE%97go-get-%E2%80%9Cgithub-com-thinkerou-favicon%E2%80%9D%E4%B8%8B%E8%BD%BD%EF%BC%8C%E7%84%B6%E5%90%8E%E5%86%8Dimport-%E2%80%9Cgithub-com-thinkerou-favicon%E2%80%9D%E5%AF%BC%E5%85%A5%E8%BF%99%E4%B8%AA%E5%8C%85%EF%BC%8Cfavicon-New%E8%BF%99%E4%B8%AA%E5%87%BD%E6%95%B0%E6%89%8D%E8%83%BD%E7%94%A8"><span class="toc-number">3.1.</span> <span class="toc-text">你得先找一个.ico或者照片啥的，放到你的项目中，这不就是前端项目的常用手段嘛。ginServer.Use(favicon.New(“.&#x2F;cartonPhone.jpg”))。然后就得go get “github.com&#x2F;thinkerou&#x2F;favicon”下载，然后再import “github.com&#x2F;thinkerou&#x2F;favicon”导入这个包，favicon.New这个函数才能用</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#restful-api%EF%BC%88GIN%E6%94%AF%E6%8C%81%EF%BC%89"><span class="toc-number">3.2.</span> <span class="toc-text">restful api（GIN支持）</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%92%B1%E4%BB%AC%E5%86%99%E5%A5%BD%E7%9A%84%E5%89%8D%E7%AB%AF%E5%8A%A8%E6%80%81%E9%9D%99%E6%80%81%E9%A1%B5%E9%9D%A2%EF%BC%8C%E7%8E%B0%E5%9C%A8%E5%B0%B1%E5%8F%AF%E4%BB%A5%E8%AF%95%E7%9D%80%E7%94%A8go%E8%B0%83%E7%94%A8%E5%91%BC%E5%BA%94%E4%BA%86"><span class="toc-number">3.3.</span> <span class="toc-text">咱们写好的前端动态静态页面，现在就可以试着用go调用呼应了</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E8%8E%B7%E5%8F%96%E8%AF%B7%E6%B1%82%E4%B8%AD%E7%9A%84%E5%8F%82%E6%95%B0"><span class="toc-number">3.4.</span> <span class="toc-text">获取请求中的参数</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E9%87%8D%E5%AE%9A%E5%90%91%E3%80%81%E8%B7%AF%E7%94%B1%E7%BB%84%E7%AD%89%E5%B0%B1%E6%98%AFcontext-xxx"><span class="toc-number">3.5.</span> <span class="toc-text">重定向、路由组等就是context.xxx</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E8%87%AA%E5%AE%9A%E4%B9%89go%E4%B8%AD%E9%97%B4%E4%BB%B6%EF%BC%9A%E6%8B%A6%E6%88%AA%E5%99%A8"><span class="toc-number">3.6.</span> <span class="toc-text">自定义go中间件：拦截器</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Beego%EF%BC%9A%E5%BF%AB%E9%80%9F%E5%BC%80%E5%8F%91go%E5%BA%94%E7%94%A8%EF%BC%8C%E6%8F%90%E4%BE%9B%E4%BA%86%E5%BE%88%E5%A4%9A%E7%8E%B0%E6%88%90%E7%9A%84%E7%BB%84%E4%BB%B6"><span class="toc-number">3.7.</span> <span class="toc-text">Beego：快速开发go应用，提供了很多现成的组件</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#Iris"><span class="toc-number">3.7.1.</span> <span class="toc-text">Iris</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Go%E8%AF%AD%E8%A8%80ORM%E5%BA%93%EF%BC%9Axorm%EF%BC%8C%E4%BD%BF%E5%BE%97%E6%95%B0%E6%8D%AE%E5%BA%93%E6%93%8D%E4%BD%9C%E9%9D%9E%E5%B8%B8%E7%AE%80%E4%BE%BF"><span class="toc-number">3.8.</span> <span class="toc-text">Go语言ORM库：xorm，使得数据库操作非常简便</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Go%E7%9A%84%E7%BB%8F%E5%85%B8%E5%BA%94%E7%94%A8%EF%BC%9AgRPC"><span class="toc-number">3.9.</span> <span class="toc-text">Go的经典应用：gRPC</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E5%B7%A8%E4%BA%BA%E7%9A%84%E8%82%A9%E8%86%80"><span class="toc-number">4.</span> <span class="toc-text">巨人的肩膀</span></a></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>Recent Post</span></div><div class="aside-list"><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/aiminminai/2024/03/28/%E9%A1%B9%E7%9B%AE%E5%BC%80%E5%8F%91%E6%80%BB%E7%BB%93%E4%B9%8BC-%E5%86%99%E4%BA%86%E4%B8%80%E4%B8%AA%E4%B8%8A%E4%BD%8D%E6%9C%BA%E9%A1%B5%E9%9D%A2%EF%BC%8C%E8%BD%AF%E4%BB%B6%E5%8D%A1%E6%AD%BB%E4%BA%86%EF%BC%9F%EF%BC%9F%EF%BC%9F/" title="项目开发总结之C#写了一个上位机页面，软件卡死了？？？">项目开发总结之C#写了一个上位机页面，软件卡死了？？？</a><time datetime="2024-03-28T15:41:40.000Z" title="Created 2024-03-28 23:41:40">2024-03-28</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/aiminminai/2024/03/27/Golang-web-http%E6%A1%86%E6%9E%B6/" title="Golang-web/http框架">Golang-web/http框架</a><time datetime="2024-03-27T15:27:12.000Z" title="Created 2024-03-27 23:27:12">2024-03-27</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/aiminminai/2024/03/24/Golang-%E7%BB%83%E5%9F%BA%E6%9C%AC%E5%8A%9F%EF%BC%9A%E6%89%8E%E9%A9%AC%E6%AD%A5%E3%80%81%E7%BB%83%E6%8A%95%E7%AF%AE/" title="Golang-练基本功：扎马步、练投篮、练运球">Golang-练基本功：扎马步、练投篮、练运球</a><time datetime="2024-03-24T15:42:23.000Z" title="Created 2024-03-24 23:42:23">2024-03-24</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/aiminminai/2024/03/15/%E8%83%BD%E4%B8%8D%E8%83%BD%E7%BB%99%E5%88%AB%E4%BA%BA%E4%B8%80%E4%B8%AA%E4%B8%8A%E6%89%8B%E5%B0%B1%E8%83%BD%E7%9C%8B%E6%87%82%E5%B0%B1%E8%83%BD%E7%94%A8%E7%9A%84%E4%B8%89%E5%B1%82%E7%A5%9E%E7%BB%8F%E7%BD%91%E7%BB%9C%EF%BC%88%E4%BB%A3%E7%A0%81%EF%BC%89%E6%A8%A1%E5%9E%8B%E5%91%A2%EF%BC%9F/" title="能不能给别人一个上手就能看懂就能用的三层神经网络（代码）模型呢？">能不能给别人一个上手就能看懂就能用的三层神经网络（代码）模型呢？</a><time datetime="2024-03-14T16:23:21.000Z" title="Created 2024-03-15 00:23:21">2024-03-15</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/aiminminai/2024/02/28/%E6%89%93%E7%A0%B4%E7%A0%82%E9%94%85%E9%97%AE-WPF%E5%8E%9F%E7%90%86-03-WPF%E6%A0%B7%E5%BC%8F%E8%AE%BE%E7%BD%AE%E5%92%8C%E6%A8%A1%E6%9D%BF%E5%8C%96%E3%80%81%E5%86%85%E8%81%94%E6%A0%B7%E5%BC%8F%E5%92%8C%E6%A8%A1%E6%9D%BF/" title="打破砂锅问-WPF原理-03-WPF样式设置和模板化、内联样式和模板">打破砂锅问-WPF原理-03-WPF样式设置和模板化、内联样式和模板</a><time datetime="2024-02-28T15:10:28.000Z" title="Created 2024-02-28 23:10:28">2024-02-28</time></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2020 - 2024 By Hu hb</div><div class="framework-info"><span>Framework </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>Theme </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="Read Mode"><i class="fas fa-book-open"></i></button><button id="darkmode" type="button" title="Switch Between Light And Dark Mode"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="Toggle between single-column and double-column"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="Setting"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="Table Of Contents"><i class="fas fa-list-ul"></i></button><button id="chat-btn" type="button" title="Chat"><i class="fas fa-sms"></i></button><button id="go-up" type="button" title="Back To Top"><span class="scroll-percent"></span><i class="fas fa-arrow-up"></i></button></div></div><div><script src="/aiminminai/js/utils.js"></script><script src="/aiminminai/js/main.js"></script><script src="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox/fancybox.umd.min.js"></script><div class="js-pjax"></div><script id="canvas_nest" defer="defer" color="0,0,255" opacity="0.7" zIndex="-1" count="99" mobile="false" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/dist/canvas-nest.min.js"></script><script id="click-heart" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/dist/click-heart.min.js" async="async" mobile="false"></script><script>(() => {
  const isChatBtn = true
  const isChatHideShow = true

  if (isChatBtn) {
    const close = () => {
      Chatra('minimizeWidget')
      Chatra('hide')
    }

    const open = () => {
      Chatra('openChat', true)
      Chatra('show')
    }

    window.ChatraSetup = {
      startHidden: true
    }
  
    window.chatBtnFn = () => {
      const isShow = document.getElementById('chatra').classList.contains('chatra--expanded')
      isShow ? close() : open()
    }
  } else if (isChatHideShow) {
    window.chatBtn = {
      hide: () => {
        Chatra('hide')
      },
      show: () => {
        Chatra('show')
      }
    }
  }

  (function(d, w, c) {
    w.ChatraID = 't3Zijv5iKg5Z5HT6v'
    var s = d.createElement('script')
    w[c] = w[c] || function() {
        (w[c].q = w[c].q || []).push(arguments)
    }
    s.async = true
    s.src = 'https://call.chatra.io/chatra.js'
    if (d.head) d.head.appendChild(s)
  })(document, window, 'Chatra')

})()</script><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div></body></html>